package com.zzyl.common.ai;


import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.core.auth.Auth;
import com.baidubce.qianfan.model.chat.ChatResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class AIModelInvoker {

    private final BaiduAIProperties baiduAIProperties;

    public String qianfanInvoker(String prompt){
        Qianfan qianfan = new Qianfan(Auth.TYPE_OAUTH, baiduAIProperties.getAccessKey(), baiduAIProperties.getSecretKey());

        ChatResponse response = qianfan.chatCompletion()
                .model(baiduAIProperties.getQianfanModel())
                .addMessage("user", prompt)
                .temperature(0.7)
                //单词最大token为2000
                .maxOutputTokens(2000)
                .responseFormat("json_object")
                .execute();

         return response.getResult();
    }
}
